import { history } from "../.umi/core/history";

export default {
    //命名空间
    namespace: 'example',

    //状态数据
    state: {
        token:'',
        checking:'0'
    },

    //初始化
    subscriptions: {
        // setup({ dispatch, history }) {  // eslint-disable-line
        //     console.log("初始化")
        // },
    },

    //异步
    effects: {
        *setUserInfo({payload}, { call, put }) {  // eslint-disable-line
            yield put({type:'save',payload})
            if(payload?.checking!='1'){
                //跳转到审核页
                history.push('/checking')
            }else{
                //跳转到首页
                history.push('/home')
            }
        },
    },

    //同步
    //更新状态的事件
    reducers: {
        save(state, action) {
            return { ...state, ...action.payload };
        },
    },

};

//异步操作
async function query() {
    const res=await fetch('/api/users').then(res => res.json());
    return res
}